package com.adui.mgt.performance.api;

import com.adui.mgt.performance.common.Result;
import com.adui.mgt.performance.entity.User;
import com.adui.mgt.performance.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/users")
public class UserApi {

    @Autowired
    private UserService userService;


    @PostMapping("/users")
    public Result findUsers(@RequestBody User user) {
        return userService.findUsers(user);
    }

    @GetMapping("/exist-flag")
    public Result existUser(@RequestParam("username") String username) {
        return Result.data(userService.existUsernameFlag(username));
    }

    @GetMapping("/{id}")
    public Result findUserById(@PathVariable("id") String id) {
        return Result.data(userService.findUserById(id));
    }

    @PostMapping("")
    public Result insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    @PutMapping("")
    public Result updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @DeleteMapping("/{id}")
    public Result deleteUser(@PathVariable("id") String id) {
        return userService.deleteUser(id);
    }

}
